package change

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models"
)

// ==================== 结算账户变更 ====================

// SettleAccountChangeRequest 结算账户变更请求
type SettleAccountChangeRequest struct {
	models.OrgBaseRequest
	// ApplyID 业务申请编号
	ApplyID string `json:"apply_id,omitempty"`
	// MerchNo 商户号
	MerchNo string `json:"merch_no,omitempty"`
	// SettleType 结算类型
	SettleType string `json:"settle_type,omitempty"`
	// AccountName 结算账户名
	AccountName string `json:"account_name,omitempty"`
	// AccountNo 账号
	AccountNo string `json:"account_no,omitempty"`
	// BankCode 开户银行
	BankCode string `json:"bank_code,omitempty"`
	// BankBranchID 开户支行编号
	BankBranchID string `json:"bank_branch_id,omitempty"`
	// BankBranchName 开户支行名称
	BankBranchName string `json:"bank_branch_name,omitempty"`
	// AccountPic 结算账户照片
	AccountPic string `json:"account_pic,omitempty"`
	// BankSetPhone 预留银行手机号码
	BankSetPhone string `json:"bank_set_phone,omitempty"`
	// CertType 收款人证件类型
	CertType string `json:"cert_type,omitempty"`
	// DelegateeIDCard 收款人证件号码
	DelegateeIDCard string `json:"delegatee_id_card,omitempty"`
	// DelegateeCertPeriodBegin 收款人证件有效期开始日期
	DelegateeCertPeriodBegin string `json:"delegatee_cert_period_begin,omitempty"`
	// DelegateeCertPeriodEnd 收款人证件有效期结束日期
	DelegateeCertPeriodEnd string `json:"delegatee_cert_period_end,omitempty"`
	// AcctLicense 结算账户公司营业执照照片
	AcctLicense string `json:"acct_license,omitempty"`
	// AcctCertFrontPic 结算账户人的身份证件正面
	AcctCertFrontPic string `json:"acct_cert_front_pic,omitempty"`
	// AcctCertBackPic 结算账户人的身份证件反面
	AcctCertBackPic string `json:"acct_cert_back_pic,omitempty"`
	// AcctAuthLetter 结算账户收款确认书
	AcctAuthLetter string `json:"acct_auth_letter,omitempty"`
	// IdentityFacePic 法人人脸图片
	IdentityFacePic string `json:"identity_face_pic,omitempty"`
	// AcctFacePic 结算账户人脸图片
	AcctFacePic string `json:"acct_face_pic,omitempty"`
	// ProofInfo 辅助证明材料
	ProofInfo []map[string]interface{} `json:"proof_info,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewSettleAccountChangeRequest 创建结算账户变更请求
func NewSettleAccountChangeRequest() *SettleAccountChangeRequest {
	req := &SettleAccountChangeRequest{}
	return req
}

// GetSensitiveFields 返回需要加密的敏感字段路径列表
func (r *SettleAccountChangeRequest) GetSensitiveFields() []string {
	// 与Python版本保持一致，定义敏感字段路径
	return []string{
		"account_name",      // 结算账户名
		"account_no",        // 账号
		"bank_set_phone",    // 预留银行手机号码
		"delegatee_id_card", // 收款人证件号码
	}
}

// SetApplyID 设置业务申请编号
func (r *SettleAccountChangeRequest) SetApplyID(applyID string) *SettleAccountChangeRequest {
	r.ApplyID = applyID
	return r
}

// SetMerchNo 设置商户号
func (r *SettleAccountChangeRequest) SetMerchNo(merchNo string) *SettleAccountChangeRequest {
	r.MerchNo = merchNo
	return r
}

// SetSettleType 设置结算类型
func (r *SettleAccountChangeRequest) SetSettleType(settleType string) *SettleAccountChangeRequest {
	r.SettleType = settleType
	return r
}

// SetAccountName 设置结算账户名
func (r *SettleAccountChangeRequest) SetAccountName(accountName string) *SettleAccountChangeRequest {
	r.AccountName = accountName
	return r
}

// SetAccountNo 设置账号
func (r *SettleAccountChangeRequest) SetAccountNo(accountNo string) *SettleAccountChangeRequest {
	r.AccountNo = accountNo
	return r
}

// SetBankCode 设置开户银行
func (r *SettleAccountChangeRequest) SetBankCode(bankCode string) *SettleAccountChangeRequest {
	r.BankCode = bankCode
	return r
}

// SetBankBranchID 设置开户支行编号
func (r *SettleAccountChangeRequest) SetBankBranchID(bankBranchID string) *SettleAccountChangeRequest {
	r.BankBranchID = bankBranchID
	return r
}

// SetBankBranchName 设置开户支行名称
func (r *SettleAccountChangeRequest) SetBankBranchName(bankBranchName string) *SettleAccountChangeRequest {
	r.BankBranchName = bankBranchName
	return r
}

// SetAccountPic 设置结算账户照片
func (r *SettleAccountChangeRequest) SetAccountPic(accountPic string) *SettleAccountChangeRequest {
	r.AccountPic = accountPic
	return r
}

// SetBankSetPhone 设置预留银行手机号码
func (r *SettleAccountChangeRequest) SetBankSetPhone(bankSetPhone string) *SettleAccountChangeRequest {
	r.BankSetPhone = bankSetPhone
	return r
}

// SetCertType 设置收款人证件类型
func (r *SettleAccountChangeRequest) SetCertType(certType string) *SettleAccountChangeRequest {
	r.CertType = certType
	return r
}

// SetDelegateeIDCard 设置收款人证件号码
func (r *SettleAccountChangeRequest) SetDelegateeIDCard(delegateeIDCard string) *SettleAccountChangeRequest {
	r.DelegateeIDCard = delegateeIDCard
	return r
}

// SetDelegateeCertPeriodBegin 设置收款人证件有效期开始日期
func (r *SettleAccountChangeRequest) SetDelegateeCertPeriodBegin(delegateeCertPeriodBegin string) *SettleAccountChangeRequest {
	r.DelegateeCertPeriodBegin = delegateeCertPeriodBegin
	return r
}

// SetDelegateeCertPeriodEnd 设置收款人证件有效期结束日期
func (r *SettleAccountChangeRequest) SetDelegateeCertPeriodEnd(delegateeCertPeriodEnd string) *SettleAccountChangeRequest {
	r.DelegateeCertPeriodEnd = delegateeCertPeriodEnd
	return r
}

// SetAcctLicense 设置结算账户公司营业执照照片
func (r *SettleAccountChangeRequest) SetAcctLicense(acctLicense string) *SettleAccountChangeRequest {
	r.AcctLicense = acctLicense
	return r
}

// SetAcctCertFrontPic 设置结算账户人的身份证件正面
func (r *SettleAccountChangeRequest) SetAcctCertFrontPic(acctCertFrontPic string) *SettleAccountChangeRequest {
	r.AcctCertFrontPic = acctCertFrontPic
	return r
}

// SetAcctCertBackPic 设置结算账户人的身份证件反面
func (r *SettleAccountChangeRequest) SetAcctCertBackPic(acctCertBackPic string) *SettleAccountChangeRequest {
	r.AcctCertBackPic = acctCertBackPic
	return r
}

// SetAcctAuthLetter 设置结算账户收款确认书
func (r *SettleAccountChangeRequest) SetAcctAuthLetter(acctAuthLetter string) *SettleAccountChangeRequest {
	r.AcctAuthLetter = acctAuthLetter
	return r
}

// SetIdentityFacePic 设置法人人脸图片
func (r *SettleAccountChangeRequest) SetIdentityFacePic(identityFacePic string) *SettleAccountChangeRequest {
	r.IdentityFacePic = identityFacePic
	return r
}

// SetAcctFacePic 设置结算账户人脸图片
func (r *SettleAccountChangeRequest) SetAcctFacePic(acctFacePic string) *SettleAccountChangeRequest {
	r.AcctFacePic = acctFacePic
	return r
}

// SetProofInfo 设置辅助证明材料
func (r *SettleAccountChangeRequest) SetProofInfo(proofInfo []map[string]interface{}) *SettleAccountChangeRequest {
	r.ProofInfo = proofInfo
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *SettleAccountChangeRequest) SetRawRequestMap(rawMap map[string]interface{}) *SettleAccountChangeRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *SettleAccountChangeRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *SettleAccountChangeRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	// 添加自己的字段
	if r.ApplyID != "" {
		baseMap["apply_id"] = r.ApplyID
	}
	if r.MerchNo != "" {
		baseMap["merch_no"] = r.MerchNo
	}
	if r.SettleType != "" {
		baseMap["settle_type"] = r.SettleType
	}
	if r.AccountName != "" {
		baseMap["account_name"] = r.AccountName
	}
	if r.AccountNo != "" {
		baseMap["account_no"] = r.AccountNo
	}
	if r.BankCode != "" {
		baseMap["bank_code"] = r.BankCode
	}
	if r.BankBranchID != "" {
		baseMap["bank_branch_id"] = r.BankBranchID
	}
	if r.BankBranchName != "" {
		baseMap["bank_branch_name"] = r.BankBranchName
	}
	if r.AccountPic != "" {
		baseMap["account_pic"] = r.AccountPic
	}
	if r.BankSetPhone != "" {
		baseMap["bank_set_phone"] = r.BankSetPhone
	}
	if r.CertType != "" {
		baseMap["cert_type"] = r.CertType
	}
	if r.DelegateeIDCard != "" {
		baseMap["delegatee_id_card"] = r.DelegateeIDCard
	}
	if r.DelegateeCertPeriodBegin != "" {
		baseMap["delegatee_cert_period_begin"] = r.DelegateeCertPeriodBegin
	}
	if r.DelegateeCertPeriodEnd != "" {
		baseMap["delegatee_cert_period_end"] = r.DelegateeCertPeriodEnd
	}
	if r.AcctLicense != "" {
		baseMap["acct_license"] = r.AcctLicense
	}
	if r.AcctCertFrontPic != "" {
		baseMap["acct_cert_front_pic"] = r.AcctCertFrontPic
	}
	if r.AcctCertBackPic != "" {
		baseMap["acct_cert_back_pic"] = r.AcctCertBackPic
	}
	if r.AcctAuthLetter != "" {
		baseMap["acct_auth_letter"] = r.AcctAuthLetter
	}
	if r.IdentityFacePic != "" {
		baseMap["identity_face_pic"] = r.IdentityFacePic
	}
	if r.AcctFacePic != "" {
		baseMap["acct_face_pic"] = r.AcctFacePic
	}
	if r.ProofInfo != nil && len(r.ProofInfo) > 0 {
		baseMap["proof_info"] = r.ProofInfo
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *SettleAccountChangeRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// SettleAccountChangeResponse 结算账户变更响应
type SettleAccountChangeResponse struct {
	models.StandardResponse
	// MerchNo 商户号
	MerchNo string `json:"merch_no,omitempty"`
	// ApplyID 业务申请编号
	ApplyID string `json:"apply_id,omitempty"`
}

// NewSettleAccountChangeResponse 创建结算账户变更响应
func NewSettleAccountChangeResponse() *SettleAccountChangeResponse {
	return &SettleAccountChangeResponse{}
}
